package Day2025_02_19;

public class LeetCode1658 {
    public int minOperations(int[] nums, int x) {
        int n = nums.length;
        int sum = 0;
        for (int i : nums) sum += i;
        if (sum < x) return -1;
        int target = sum - x;
        int maxLen = -1;
        for (int left = 0, right = 0; right < n; right++) {
            target -= nums[right];
            while (target < 0) target += nums[left++];
            if (target == 0) maxLen = Math.max(right - left + 1, maxLen);
        }
        return maxLen == -1 ? -1 : n - maxLen;
    }

    public static void main(String[] args) {
        int[] nums = {8828,9581,49,9818,9974,9869,9991,10000,10000,10000,9999,9993,9904,8819,1231,6309};
        System.out.println(new LeetCode1658().minOperations(nums, 134365));
    }
}
